package org.estela.util;

/**
 * StopWatch is used for method measurement performance
 * and other related statistics.
 *  
 * @since 1.00
 * @version $Revision$
 */
public final class StopWatch {

	/** Initial time in ms */
	public final long t0 = System.currentTimeMillis();
	
	/** Initial time in nano */
	public final long n0 = System.nanoTime();

	/**
	 * Starts counting.
	 * @return Returns a new instance of <code>StopWatch</code>.
	 */
	static public StopWatch start() {
		return new StopWatch();
	}

	/**
	 * @return Returns the ellapsed time in ms.
	 */
	public long millisEllapsed() {
		return System.currentTimeMillis() - t0;
	}

	/**
	 * @return Returns the ellapsed time in seconds.
	 */
	public double secondsEllapsed() {
		return millisEllapsed() / 1000.0;
	}
	
	/**
	 * @return Returns the ellapsed time in nano.
	 */
	public long nanoEllapsed() {
		return System.nanoTime() - n0;
	}
	
	private StopWatch() {
	}
}
